package my.study.org.mongodb.factory.impl;

import java.net.UnknownHostException;

import my.study.org.mongodb.constant.MongoDBConstant;
import my.study.org.mongodb.factory.MongoFactory;

import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoException;


public class MongoFactoryImpl implements MongoFactory {
	private static MongoFactoryImpl instance = new MongoFactoryImpl();
	
	public static MongoFactory getMongoFactory() {
		return MongoFactoryImpl.instance;
	}
	
	public Mongo getMongo() {
		try {
			return new Mongo(MongoDBConstant.MONGO_HOST,
					MongoDBConstant.MONGO_PORT);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (MongoException e) {
			e.printStackTrace();
		};
		return null;
	}
	
	public DB getMongoDB(String dbName) {
		return getMongo().getDB(dbName);
	}

}
